package ee.videorentalstore.protocols.commands.filmmanagercommands;

import java.util.List;

import ee.videorentalstore.inventories.Film;
import ee.videorentalstore.inventories.FilmInventory;
import ee.videorentalstore.protocols.commands.Command;

public class RemoveAFilmCommand extends Command
{
	private final int FILM_ID_POSITION_IN_SPLITTED_INSTRUCTIONS_LIST = 1;
	
	
	@Override
	public String getCommandDescription() 
	{
		return "REMOVE A FILM";
	}
	
	
	@Override
	public void executeCommand(String inputStreamInstructionsToProcess) 
	{
		List<String> splittedInstructionsList = 
				getSplittedInputStreamInstructionsToProcess(inputStreamInstructionsToProcess);
		Integer filmID = getSpecificIntegerValueOutOfSplittedInstructionsList(
				splittedInstructionsList, FILM_ID_POSITION_IN_SPLITTED_INSTRUCTIONS_LIST);
		if (filmID != null)
		{
			boolean filmWithGivenIDExists = FilmInventory.getInstance().doesContainFilmByID(filmID.intValue());
			if (filmWithGivenIDExists)
			{
				boolean filmIsRentedOut = FilmInventory.getInstance().getIsFilmRentedOutByItsID(filmID.intValue());
				if (filmIsRentedOut)
				{
					System.out.println("Film has been rented out and can not be deleted!");
				}
				else
				{
					Film filmToRemove = FilmInventory.getInstance().getFilmByID(filmID.intValue());
					FilmInventory.getInstance().removeFilm(filmToRemove);
					System.out.println("Film has been deleted successfully!");
				}
			}
			else
			{
				System.out.println("There is no film in inventory with given ID!");
			}
		}
		else
		{
			System.out.println("Command could not be executed due to inserted instructions errors!");
		}
	}
}
